<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05-ajax-get</title>
    <script>
        window.onload=function (ev) {
            var oBtn=document.querySelector("button");
            oBtn.onclick=function (ev1) {
                var xhr;
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xhr=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xhr=new ActiveXObject("Microsoft.XMLHTTP");
                }
                /*
                在IE浏览器中, 如果通过Ajax发送GET请求, 那么IE浏览器认为
                同一个URL只有一个结果
                05-ajax-get.txt === abc

                console.log(Math.random());
                console.log(new Date().getTime());
                 */
                xhr.open("GET","05-ajax-get.txt?t="+(new Date().getTime()),true);
                xhr.send();
                xhr.onreadystatechange=function (ev2) {
                    if(xhr.readyState===4){
                        if(xhr.status>=200 && xhr.status<300 ||xhr.status===304){
                            alert(xhr.responseText);
                        } else{
                            alert("请求失败");
                        }
                    }
                }
            }
        }
    </script>
</head>
<body>
<button>发送请求</button>
</body>
</html>